package cn.qiao.sbc;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;
 
public class FSWebSocketClient extends WebSocketClient {
 
    public FSWebSocketClient(URI serverUri) {
        super(serverUri);
    }
 
    @Override
    public void onOpen(ServerHandshake handshakedata) {
        // 连接打开时的处理
        send("originate {endpoint: loopback, app: answer, appArgs: 12345, channel: {socket: tcp://127.0.0.1:8084}}");
    }
 
    @Override
    public void onMessage(String message) {
        // 收到消息时的处理
        System.out.println(message);
    }
 
    @Override
    public void onClose(int code, String reason, boolean remote) {
        // 连接关闭时的处理
        System.out.println("Connection closed");
    }
 
    @Override
    public void onError(Exception ex) {
        // 发生错误时的处理
        ex.printStackTrace();
    }
 
    public static void main(String[] args) {
        try {
            FSWebSocketClient client = new FSWebSocketClient(new URI("ws://localhost:8080/ws"));
            client.connect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}